<template>
  <div>
    <div class="home_nav_one">
      <div class="z">
        admin logout
        <template>
          <van-icon name="cart-o" size="24px" color="red" @click="gwc"/>
        </template>
      </div>
    </div>
    <div class="home_nav_tow">
      <button class="ads">哈哈哈哈</button>
    </div>
    <div class="home_main">
      <nav>
        <el-row>
          <el-button type="primary" @click="priceUp">价格升序</el-button>
          <el-button type="success" @click="priceDown">价格降序</el-button>
        </el-row>
      </nav>
      <div class="home_content">
        <div class="home_right">
          <h3>P R I C E:</h3>
          <ul>
            <li v-for="(item, index) in conlist" :key="index" @click="px(item)">{{item.title}}</li>
          </ul>
        </div>
        <div class="home_left">
          <div class="home_con" v-for="(item, index) in conlist2" :key="index">
            <img :src="item.productImage" class="img" alt />
            <span class="s1">{{item.salePrice}}元</span>&nbsp;&nbsp;&nbsp;
            <span class="s2">{{item.productName}}</span>
            <el-row>
              <el-button type="warning" plain class="jr" @click="cart(item)">加入购物车</el-button>
            </el-row>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import axios from "axios";
export default {
  data() {
    return {
      conlist: [],
      conlist2: [],
      list:[],
    };
  },
  computed: {
    tolist() {
      return this.$store.state.tolist;
    },
  },
  created() {
    this.$store.dispatch("ABC");
  },
  mounted() {
    axios.get("http://localhost:8080/data1.json").then((res) => {
      console.log(res);
      this.conlist = res.data.result.slider;
    });
    window.addEventListener("scroll", this.onScroll);
    axios.get("http://localhost:8080/data1.json").then((res) => {
      console.log(res);
      this.conlist2 = res.data.result.list;
    });
  },
  methods: {
    priceUp() {
      this.conlist2.sort((a, b) => {
        return a.salePrice - b.salePrice;
      });
    },
    onScroll() {
      // 或取整个文档的高度
      var docHeight = document.documentElement.scrollHeight;
      // 或取文档可滚动距离
      var scollOffset = document.documentElement.scrollTop;
      // 或取窗口的高度
      var windowHeight = document.documentElement.clientHeight;
      if (docHeight - scollOffset - windowHeight === 0) {
        this.isLoading = true;
        window.setTimeout(() => {
          axios.get("http://localhost:8080/data1.json").then((res) => {
            this.list = [...this.list, ...res.data.result.list];
            this.isLoading = true;
            console.log(res.data.result.list);
          });
        }, 3000);
      }
    },
    price() {
        this.$store.commit("price")

    },
    defaul() {
      this.$store.commit("defaul")
    },
    cart(item) {
      this.$store.dispatch("LB_CAR", item);
    },
    priceDown() {
      this.conlist2.sort((a, b) => {
        return b.salePrice - a.salePrice;
      });
    },
    cart(item) {
      this.$store.dispatch("LB_CAR", item);
    },
    gwc() {
      this.$router.push({
        path: "/About",
      });
    },
  },
};
</script>
<style scoped>
.home {
  width: 100%;
  height: 100vh;
}
.home_nav_one {
  width: 100%;
  height: 7vh;
  line-height: 7vh;
}
.z {
  width: 150px;
  height: 6vh;
  margin-left: 87%;
}
.home_nav_tow {
  width: 100%;
  height: 6vh;
  line-height: 6vh;
  background: rgba(0, 0, 0, 0.094);
}
.home_main {
  width: 100%;
  height: 87vh;
}
.home_main nav {
  margin: 0 auto;
  width: 80%;
  height: 7vh;
  background: #fff;
  display: flex;
}
.home_content {
  width: 80%;
  height: 79vh;
  background: rgba(255, 192, 203, 0.148);
  margin: 0 auto;
  display: flex;
  justify-content: center;
}
.home_right {
  width: 25%;
  height: 79vh;
  background: rgba(135, 207, 235, 0.162);
}
.home_left {
  width: 80%;
  background: rgba(255, 192, 203, 0.175);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  overflow: scroll;
}
h3 {
  text-align: center;
}
ul li {
  list-style: none;
  width: 100%;
  height: 10vh;
  text-align: center;
  line-height: 10vh;
  /* border: 1px solid #000; */
}
.img {
  width: 100%;
  height: 75%;
}
ul li:hover {
  border-left: 4px solid red;
  color: red;
}
.home_con {
  width: 20%;
  height: 39vh;
  border: 1px solid rgba(0, 0, 0, 0.068);
  background: white;
}
.s1 {
  font-size: 15px;
  color: red;
}
.s2 {
  font-size: 14px;
  /* color: red; */
}
.jr {
  width: 100%;
  height: 5vh;
  /* line-height: 3vh; */
}
.ads {
  display: block;
}
@media screen and (max-width: 1100px) {
  .ads {
    display: none;
  }
  .home_con {
    width: 30%;
    height: 39vh;
    border: 1px solid rgba(0, 0, 0, 0.068);
    background: white;
  }
}
@media screen and (max-width: 686px) {
  .home_con {
    width: 70%;
    height: 20vh;
    border: 1px solid rgba(0, 0, 0, 0.068);
    background: white;
  }
  .home_right{
    display: none;
  }
  .img {
  width: 20%;
  height: 75%;
}
}
</style>